<?php

class RemoteController extends App_Controller_Action
{
  
  /*
  from service page, login directly
  */
  public function directLoginAction()
  {
    // $skey is the stored password in service member table 	
  	$client_id = $this->getRequest()->getParam('client_id');
    $security_key = $this->getRequest()->getParam('security_key');
    //Zend_Debug::dump($dpt_account_id);
    //exit; 
    
    if ($client_id == -1 || $client_id == -2)
    {
    
    }
    else
    {
    	$model_service = new Model_Service();
	    $info = $model_service->getClientServiceInfoByKey($client_id, $security_key);  
	    
	    $client_id = $info['client_id'];
	    $dpt_id = $info['client_id'];
	    $dpt_account_id = $info['dpt_account_id'];
	    $dpt_account_login = $info['dpt_account_login'];
	    
	    $security_key = "";
	    $model_service->updateKey($dpt_id, $dpt_account_id, $client_id, $security_key); // clean key
	    
	    $session = $this->getSession();
	    $storage = new App_Auth_Storage_Session($session,'client');
	          //Zend_Debug::dump($storage->read());
	          //Zend_Debug::dump($module_name);       
	    $storage->write(array(
	                    'user_id'=>$client_id,
                    	'user_name'=>$dpt_account_login,
                    	'user_role'=>'client'));
        //Zend_Debug::dump($storage->read());exit;
    }  
    $this->_redirect("/client");
    exit;
  }
}